<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseBills {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_intChargeId;
	protected $m_intDepartmentId;
	protected $m_intDiagnosisId;
	protected $m_intAmount;
	protected $m_intCreatedBy;
	protected $m_strCreatedOn;
	protected $m_intUpdatedBy;
	protected $m_strUpdatedOn;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getChargeId(){
		return $this->m_intChargeId;
	}

	public function getDepartmentId(){
		return $this->m_intDepartmentId;
	}

	public function getDiagnosisId(){
		return $this->m_intDiagnosisId;
	}

	public function getAmount(){
		return $this->m_intAmount;
	}

	public function getCreatedBy(){
		return $this->m_intCreatedBy;
	}

	public function getCreatedOn(){
		return $this->m_strCreatedOn;
	}

	public function getUpdatedBy(){
		return $this->m_intUpdatedBy;
	}

	public function getUpdatedOn(){
		return $this->m_strUpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setChargeId( $ChargeId ){
		$this->m_intChargeId = $ChargeId;
	}

	public function setDepartmentId( $DepartmentId ){
		$this->m_intDepartmentId = $DepartmentId;
	}

	public function setDiagnosisId( $DiagnosisId ){
		$this->m_intDiagnosisId = $DiagnosisId;
	}

	public function setAmount( $Amount ){
		$this->m_intAmount = $Amount;
	}

	public function setCreatedBy( $CreatedBy ){
		$this->m_intCreatedBy = $CreatedBy;
	}

	public function setCreatedOn( $CreatedOn ){
		$this->m_strCreatedOn = $CreatedOn;
	}

	public function setUpdatedBy( $UpdatedBy ){
		$this->m_intUpdatedBy = $UpdatedBy;
	}

	public function setUpdatedOn( $UpdatedOn ){
		$this->m_strUpdatedOn = $UpdatedOn;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into BILLS (patient_id, charge_id, department_id, diagnosis_id, amount, created_by, created_on, updated_by, updated_on) values (" . $this->getPatientId() . ", " . $this->getChargeId() . ", " . $this->getDepartmentId() . ", " . $this->getDiagnosisId() . ", " . $this->getAmount() . ", " . $this->getCreatedBy() . ", now() , " . $this->getUpdatedBy() . ", NULL )");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE BILLS set  patient_id= " . $this->getPatientId() . ", charge_id= " . $this->getChargeId() . ", department_id= " . $this->getDepartmentId() . ", diagnosis_id= " . $this->getDiagnosisId() . ", amount= " . $this->getAmount() . ", created_by= " . $this->getCreatedBy() . ", updated_by= " . $this->getUpdatedBy() . ",updated_on = now()  where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM bills WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'bills'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}